package top.hzy520.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.HeaderHttpSessionStrategy;
import org.springframework.session.web.http.HttpSessionStrategy;
import top.hzy520.common.constants.Parameter;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 10:31 2018/6/10
 */
@Configuration
@EnableRedisHttpSession
public class HttpSessionConfig {
   @Autowired
   private Parameter parameter;
    @Bean
    public HttpSessionStrategy httpSessionStrategy(){return new HeaderHttpSessionStrategy();}

    @Bean
    public JedisConnectionFactory connectionFactory(){
        JedisConnectionFactory connectionFactory=new JedisConnectionFactory();
        connectionFactory.setHostName(parameter.getRedisHost());
        connectionFactory.setPort(Integer.valueOf(parameter.getRedisPort()));
        connectionFactory.setTimeout(2000);
        return connectionFactory;
    }
}
